package com.cd2cd.code_template.configuration.handler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cd2cd.code_template.util.CommUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import static com.cd2cd.code_template.configuration.constants.ServiceCode.ACCESS_DENIED;

/**
 * 自定义无权访问处理类
 */
@Slf4j
@Component
public class RestAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) {
        log.error("{}", ACCESS_DENIED);
        CommUtils.returnCode(response, ACCESS_DENIED);
    }

}
